<template>
	<view class="container">
		<view class="tui-cmt-primary bg-white">
			<view class="tui-cmt-cell tui-cell-last">
				<view class="tui-header-box">
					<view class="tui-userinfo-box">
						<image :src="commentDetail.avatar" class="tui-avatar"></image>
						<view class="tui-nickname-box">
							<view class="tui-cmt-nickname">{{commentDetail.nickName}}</view>
							<view class="tui-cmt-time">{{commentDetail.createDate}}</view>
						</view>
					</view>
				</view>
				<view class="tui-cmt-content text-content">{{commentDetail.content}}</view>
			</view>
		</view>
		<view class="tui-empty"></view>
		<view class="tui-cmt-title bg-white">全部回复（{{commentDetail.replyCount}}）</view>
		<view class="tui-cmtbox bg-white">
			<view class="tui-cmt-cell" v-for="(item, index) in replyList" :key="index">
				<view class="tui-header-box">
					<view class="tui-userinfo-box">
						<image :src="item.avatar" class="tui-avatar"></image>
						<view class="tui-nickname-box">
							<view class="tui-cmt-nickname">{{ item.nickName }}</view>
							<view class="tui-cmt-time">{{ item.createDate }}</view>
						</view>
					</view>
				</view>
				<view class="tui-cmt-content text-content">{{ item.content }}</view>
			</view>
		</view>

		<!--加载loadding-->
		<tui-loadmore v-if="loadding" :index="3" type="primary"></tui-loadmore>
		<tui-nomore v-if="!pullUpOn" backgroundColor="#f1f1f1" text="没有更多回复"></tui-nomore>
		<!--加载loadding-->
		<view class="tui-safearea-bottom"></view>
		
		<view class="tui-operation">
			<!--处理iphonex xr 等手机底部兼容-->
			<view class="tui-operation-inner">
				<view class="tui-btn-comment" @tap="btnCmt">回复楼主...</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			collectionUid: '',
			commentUid: '',
			commentDetail: {},
			replyList: [],
			pageNum: 1,
			pageSize: 10,
			loadding: false,
			pullUpOn: true
		};
	},
	async onLoad(option) {
		if (option.data) {
			let data = JSON.parse(option.data)
			this.collectionUid = data.collectionUid,
			this.commentUid = data.commentUid
		}
	},
	async onShow() {
		this.getCommentDetail()
		this.getReplyList('onLoad')
	},
	methods: {
		getCommentDetail() {
			this.fetch.request("/api/wxmini/getCommentDetail", "POST", {
				commentUid: this.commentUid
			}, false, true, true, this)
			.then((res) => {
				if (res.code == 0) {
					this.commentDetail = res.data
				}
			}).catch(() => {})
		},
		getReplyList(type) {
			if (type == 'onLoad' || type == 'refresh') {
				this.pageNum = 1
				this.pullUpOn = true
				this.loadding = false
			}
			this.fetch.request("/api/wxmini/getReplyList", "POST", {
				parentId: this.commentUid,
				collectionUid: this.collectionUid,
				pageNum: this.pageNum,
				pageSize: this.pageSize
			}, false, true, false, this)
			.then((res) => {
				if (res.code == 0) {
					let data = res.data
					if (type != 'loadMore') {
						this.replyList = []
					}
					data.rows.forEach((item) => {
						this.replyList.push(item)
					})
					if (type == 'refresh') {
						setTimeout(() => {
							uni.stopPullDownRefresh();
						}, 200);
					}
					if (type == 'loadMore') {
						this.loadding = false;
					}
					if (this.replyList.length >= data.total) {
						this.pullUpOn = false
					}
				}
			}).catch(() => {})
		},
		btnCmt: function() {
			let data = {
				collectionUid: this.collectionUid,
				commentUid: this.commentUid
			}
			uni.navigateTo({
				url: `../comment/comment?data=${JSON.stringify(data)}`
			});
		}
	},
	//页面相关事件处理函数--监听用户下拉动作
	onPullDownRefresh: function() {
		this.getReplyList('refresh');
	},
	// 页面上拉触底事件的处理函数
	onReachBottom: function() {
		if (this.loadding || !this.pullUpOn) {
			return;
		}
		this.loadding = true;
		this.pageNum++;
		this.getReplyList('loadMore')
	}
};
</script>

<style>

.container {
	padding-bottom: 110rpx;
	box-sizing: border-box;
}

.tui-empty {
	width: 100%;
	height: 10rpx;
}

.tui-cmt-title {
	font-size: 30rpx;
	font-weight: bold;
	position: relative;
	padding: 20rpx 30rpx;
	box-sizing: border-box;
	margin-bottom: 20rpx;
}

.tui-cmt-title::after {
	content: '';
	position: absolute;
	left: 12rpx;
	top: 30%;
	width: 6rpx;
	height: 36%;
	background: #8c7866;
}

.tui-cmt-cell {
	width: 100%;
	padding: 26rpx 30rpx;
	box-sizing: border-box;
	position: relative;
}

.tui-cmt-cell::after {
	content: '';
	position: absolute;
	border-bottom: 1rpx solid #eaeef1;
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
	bottom: 0;
	right: 0;
	left: 0;
}

.tui-cell-last::after {
	border-bottom: 0 !important;
}

.tui-header-box {
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 28rpx;
}

.tui-userinfo-box {
	display: flex;
	align-items: center;
}

.tui-avatar {
	width: 64rpx;
	height: 64rpx;
	border-radius: 32rpx;
	display: block;
	flex-shrink: 0;
}

.tui-nickname-box {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	padding-left: 12rpx;
	padding-top: 4rpx;
	height: 60rpx;
}

.tui-cmt-nickname {
	/* color: #5677fc; */
	color: #9a9a9a;
	line-height: 28rpx;
}

.tui-cmt-time {
	font-size: 24rpx;
	line-height: 24rpx;
	color: #9a9a9a;
	transform: scale(0.8);
	transform-origin: 0 100%;
}

.tui-fabulous {
	color: #9a9a9a;
}

.tui-fabulous text {
	padding-right: 4rpx;
	font-size: 24rpx;
}

.tui-cmt-content {
	color: #333;
	text-align: justify;
	padding-top: 16rpx;
	word-break: break-all;
	word-wrap: break-word;
}

.tui-reply-box {
	border-radius: 8rpx;
	overflow: hidden;
	margin-top: 16rpx;
}

.tui-cell-class {
	flex-direction: column;
	justify-content: flex-start !important;
	padding: 20rpx !important;
	text-align: justify;
	word-break: break-all;
	word-wrap: break-word;
}

.tui-flex-1 {
	flex: 1;
	width: 100%;
}

.tui-reply-nickname {
	font-size: 24rpx;
	color: #7a7a7a;
	padding-bottom: 8rpx;
}

.tui-operation {
	width: 100%;
	padding: 0 30rpx;
	box-sizing: border-box;
	overflow: hidden;
	background: rgba(255, 255, 255, 0.95);
	position: fixed;
	left: 0;
	bottom: 0;
	z-index: 99999;
	padding-bottom: env(safe-area-inset-bottom);
}

.tui-operation-inner {
	height: 100rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	/* padding-bottom: env(safe-area-inset-bottom); */
}

.tui-safearea-bottom {
	width: 100%;
	height: env(safe-area-inset-bottom);
}

.tui-operation::before {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	left: 0;
	border-top: 1rpx solid #eaeef1;
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
}

.tui-btn-comment {
	height: 64rpx;
	width: 100%;
	background: #ededed;
	color: #999;
	border-radius: 8rpx;
	font-size: 28rpx;
	display: flex;
	align-items: center;
	padding-left: 20rpx;
	box-sizing: border-box;
	padding-top: 0;
}

.tui-primary {
	color: #5677fc;
}
</style>
